<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!-- import CSS -->
		<script src="../../js/commonCss.js"></script>
		<title>保险超级课堂-保险公司热销产品</title>
	</head>
	<body>
		<div id="app" v-cloak>
			<div class="pd10 border-bottom ft-14 h40">
				<a href="insuranceProduct.html">
					<el-button type="text" icon="el-icon-arrow-left">保险超级课堂(学习情况)</el-button>
				</a>
				<el-button class="f-r" type="primary" icon="el-icon-plus" @click="addCont">添加视频</el-button>
			</div>
			<div class="pd10">		
				<el-form :inline="true" :model="formInline" class="demo-form-inline">					
					<el-form-item>
						<el-input v-model="formInline.name" type="text" placeholder="名称"></el-input>
					</el-form-item>
					<el-form-item>
						<el-select v-model="formInline.company" placeholder="请选择保险公司">
							<el-option :label="item.label" :value="item.value" v-for="item in companyArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-select v-model="formInline.category" placeholder="请选择产品类别">
							<el-option :label="item.label" :value="item.value" v-for="item in categoryArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search">查询</el-button>
					</el-form-item>
				</el-form>
				<el-table :data="tableData" stripe border style="width: 100%">
					<el-table-column prop="name" label="标题"></el-table-column>
					<el-table-column prop="video" label="视频">
						<template slot-scope="scope">
							<img :src="scope.row.video" min-width="92" height="92" />
						</template>
					</el-table-column>
					<el-table-column prop="company" label="保险公司"></el-table-column>					
					<el-table-column prop="category" label="产品类别">
						<template slot-scope="scope">
							{{({"1":"小白入门","2":"防坑指南","3":"重疾病专题","4":"医疗险专题"}[scope.row.category])}}							
						</template>
					</el-table-column>
					<el-table-column prop="time" label="上传时间"></el-table-column>
					<el-table-column label="操作">
						<template slot-scope="scope">
							<el-button @click="handleEdit(scope.row)" type="text" size="medium">编辑</el-button>
							<el-button @click="handleDelete(scope.row)" type="text" size="medium" class="color-F56C6C">删除</el-button>
						</template>
					</el-table-column>
				</el-table>				
				<!-- 分页 -->
				<div class="bottomstate">
					<el-pagination class="f-r mt5" background @current-change="handleCurrentChange" :current-page="page" :page-size="limit" layout="total,prev, pager, next,jumper"
					 :total="total" ></el-pagination>
				</div>
			</div>
			<!-- 修改 -->
			<el-dialog :title="title" :visible.sync="dialogFormVisible">
				<el-form :model="form" label-width="120px">
					<el-form-item label="视频:" >
						<el-upload class="avatar-uploader" :action="ImgApiMore" :show-file-list="false" :on-success="handleAvatarSuccess">
							<img v-if="video" :src="video" class="avatar">
							<i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>
					</el-form-item>
					<el-form-item label="标题:" >
						<el-input v-model="form.name" autocomplete="off" style="width:300px;"></el-input>
					</el-form-item>
					<el-form-item label="保险公司:" >						
						<el-select v-model="form.company" placeholder="请选择保险公司">
							<el-option :label="item.label" :value="item.value" v-for="item in companyArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="产品类别:" >						
						<el-select v-model="form.category" placeholder="请选择产品类别">
							<el-option :label="item.label" :value="item.value" v-for="item in categoryArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="所属省行:" >						
						<el-select v-model="form.province" placeholder="请选择省行">
							<el-option :label="item.label" :value="item.value" v-for="item in provinceArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
				</el-form>
				<div class="dialog-footer text-r">
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="onSubmit">确 定</el-button>
				</div>
			</el-dialog>
		</div>
	</body>
	<script src="/jeefast/elementui-lib/lib/vue.js"></script>
	<script src="/jeefast/elementui-lib/lib/index.js"></script>
	<script src="/jeefast/js/jquery-1.9.1.min.js"></script>
	<script src="/jeefast/js/axios.js"></script>
	<script src="/jeefast/js/data.js"></script>
	<script>
		var app = new Vue({
			el: "#app",
			mixins: [mix],
			data: function() {
				return {
					formInline:{
						name:"",
						company:"",
						category:""
					},
					companyArr:[{
						value: '1',
						label: '人寿'
					},{
						value: '1',
						label: '泰寿'
					},{
						value: '1',
						label: '中英'
					}],
					categoryArr:[{
						value: '1',
						label: '小白入门'
					},{
						value: '2',
						label: '防坑指南'
					},{
						value: '3',
						label: '重疾病专题'
					},{
						value: '3',
						label: '寿险专题'
					},{
						value: '4',
						label: '医疗险专题'
					},{
						value: '5',
						label: '意外险专题'
					}],
					provinceArr:[{
						value: '1',
						label: '中国银行'
					},{
						value: '1',
						label: '建设银行'
					}],
					tableData: [{
						id:1,
						name:"定寿新概念：时间越长",
						video:"https://goss.veer.com/creative/vcg/veer/800water/veer-154192102.jpg",
						company:"国寿",
						category:"1",
						time:"2020年2月13日 17:51:26"
					},{
						id:2,
						name:"定寿新概念：时间越长",
						video:"https://goss.veer.com/creative/vcg/veer/800water/veer-138717127.jpg",
						company:"华夏",
						category:"2",
						time:"2020年2月13日 17:51:26"
					}],	
					// 修改
					dialogFormVisible: false,
					ImgApiMore: uploadPic,
					video: "",
					form: {
						name: "",
						video: "",
						company:"",
						category:"",
						province:""
					},
				}
			},
			methods: {
				search:function(){
					console.log(this.formInline)
				},
				// 添加
				addCont:function(){
					this.title="添加视频"
					this.dialogFormVisible = true
				},
				/* 单张上传图片 */
				handleAvatarSuccess: function(res, file) {
					this.video = URL.createObjectURL(file.raw);
					this.form.video = file.name;
				},
				// 删除
				handleDelete:function(row){
					let that = this
					that.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						that.$message({
							type: 'success',
							message: '删除成功!'
						});
					}).catch(() => {
						that.$message({
							type: 'info',
							message: '已取消删除'
						});          
					});
				},
				handleEdit:function(row){
					console.log(row)
					this.title="修改视频"
					this.dialogFormVisible=true
				},
				// 确定
				IsNull: function() {
					let flag = false;
					if (this.form.video == "") {
						this.$message.error('视频不能为空');
						return flag = true;
					}
					if (this.form.name == "") {
						this.$message.error('名称不能为空');
						return flag = true;
					}
					if (this.form.company == "") {
						this.$message.error('保险公司不能为空');
						return flag = true;
					}
					if (this.form.category == "") {
						this.$message.error('产品类别不能为空');
						return flag = true;
					}
					if (this.form.province == "") {
						this.$message.error('所属省行不能为空');
						return flag = true;
					}
				},
				onSubmit:function(){
					let that = this;
					if (that.IsNull()) {
						return;
					}
					console.log('===',this.form)
					
					this.dialogFormVisible = false
				},
			},
			created() {
				
			},
		});
	</script>
</html>
